package com.example.controller;

import com.example.pojo.Dept1;
import com.example.pojo.Result;
import com.example.service.Dept1Service;
import com.sun.corba.se.spi.resolver.Resolver;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/depts")
public class Dept1Controller {
    //我有了
    @Autowired
     Dept1Service dept1Service;
    @GetMapping
    public Result list(){
        log.info("查询所有部门数据");
        List<Dept1> dept1List=dept1Service.list();
        return Result.success(dept1List);
    }
    //我好了
    @PostMapping
    public Result add(@RequestBody Dept1 dept1){
        log.info("新增部门数据 dept1: {}",dept1);
        dept1Service.add(dept1);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result SelectById(@PathVariable Integer id){
        log.info("根据id查询部门,回显数据");
        Dept1 dept1=dept1Service.SelectById(id);
        return Result.success(dept1);
    }
    @PutMapping
    public Result update(@RequestBody Dept1 dept1){
        log.info("修改数据: {}",dept1);
        dept1Service.update(dept1);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result DeleteByid(@PathVariable Integer id){
        log.info("根据id删除部门");
       dept1Service.DeleteByid(id);
        return Result.success();
    }
}
